package com.sgb.member.weight;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatEditText;

import com.lxj.xpopup.core.CenterPopupView;
import com.sgb.member.R;
import com.sgb.member.entity.MemberLeverBean;
import com.swgk.core.util.MToast;

/**
 * 会员等级评定
 */
@SuppressLint("ViewConstructor")
public class MemberLeverRatPopup extends CenterPopupView {

    MemberLeverBean leverBean;
    SimpleResult<MemberLeverBean> mSimpleResult;
    AppCompatEditText editText;
    private String editStandard;

    public MemberLeverRatPopup(@NonNull Context context, MemberLeverBean bean, SimpleResult<MemberLeverBean> simpleResult) {
        super(context);
        leverBean = bean;
        mSimpleResult = simpleResult;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_member_lever_rat;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate() {
        super.onCreate();
        findViewById(R.id.iv_close).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        findViewById(R.id.tv_ok).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                /*if (TextUtils.isEmpty(editStandard)) {
                    MToast.showToast(getContext(), "请输入会员等级评定标准");
                    return;
                }*/
                leverBean.setStandard(editStandard);
                if (mSimpleResult != null) {
                    mSimpleResult.onResult(leverBean);
                }
                dismiss();
            }
        });
        findViewById(R.id.tv_cancel).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        TextView tvLever = findViewById(R.id.tv_lever);
        TextView tvNumber = findViewById(R.id.tv_edit_number);
        editText = findViewById(R.id.edit_standard);
        tvLever.setText(leverBean.getLevel());
        tvNumber.setText("已输入 0/300");
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (!TextUtils.isEmpty(s.toString())) {
                    editStandard = s.toString();
                } else {
                    editStandard = "";
                }
                tvNumber.setText("已输入 " + editStandard.length() + "/300");
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        editText.setText(leverBean.getStandard());
    }
}
